<?php
// 应用公共文件
function success($data, $message = '操作成功'){
    return [
        'code' => 0,
        'message' =>$message,
        'data' => $data,
    ];
}

function error($data = null, $error_code = -1, $message = ''){
    $error_config = error_config();
    if(!isset($error_config[$error_code])) $error_code = -1;
    if(empty($message)) $message = $error_config[$error_code];
    return [
        'code' => $error_code,
        'message' => $message,
        'data' => $data,
    ];
}

function error_config(){
    return $error_config = [
        -1 => '操作出错',
    ];
}

function api_success($data){
    return json_encode(success($data));
}

function api_error($data = null, $error_code = -1, $message = ''){
    return json_encode(error($data, $error_code, $message));
}
